package designpattern.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;

import designpattern.responsibility.ConcreteHandler1;
import designpattern.responsibility.ConcreteHandler2;

@Configuration // 配置注解
@ComponentScan("designpattern.responsibility")
@EnableAspectJAutoProxy(proxyTargetClass = true) // 动态代理的注解启动
public class MyAnnotationApplicationContext {

    @Bean
    public ConcreteHandler1 concreteHandler1() {
        ConcreteHandler1 concreteHandler1 = new ConcreteHandler1();
        concreteHandler1.setSuccessor(concreteHandler2());
        concreteHandler1.setName("h1");
        return concreteHandler1;
    }

    @Bean
    public ConcreteHandler2 concreteHandler2() {
        ConcreteHandler2 concreteHandler2 = new ConcreteHandler2();
        concreteHandler2.setName("h2");
        return concreteHandler2;
    }

}
